//
//  TyperwriteLabelVC.swift
//  SwiftLearning
//
//  Created by 黄龙 on 2024/1/31.
//

import UIKit

class TyperwriteLabelVC: BasicNavibarVC {
    var mTyper:TQQTyperwriteLabel?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.rightBar.title = "打印"
    }
    

    override func initView() {
        mTyper = TQQTyperwriteLabel(frame: CGRect(x: 15, y: 15, width: screen_W-30, height: 200))
        if let typerwrite = mTyper{
            workView.addSubview(typerwrite)
            typerwrite.numberOfLines = 0
            typerwrite.text = "人生如寄，多忧何为。\n今我不乐，岁月如驰。\n汤汤川流，中有行舟。\n随波转薄，有似客游。\n策我良马，被我轻裘。\n载驰载驱，聊以忘忧。\n\n一别都门三改火，天涯踏尽红尘。\n依然一笑作春温。\n无波真古井，有节是秋筠。\n惆怅孤帆连夜发，送行淡月微云。\n尊前不用翠眉颦。\n人生如逆旅，我亦是行人。"
            typerwrite.textColor = workView.backgroundColor //相当于将文字隐藏，然后通过设置attributedText逐个显示出来，模仿出打印的效果
            typerwrite.typer_color = .systemGreen
            typerwrite.playSound = true
            typerwrite.font = .systemFont(ofSize: 20)
            typerwrite.sizeToFit() //会在前面设置的frame.orgin基础上调整宽高（15,15,384,200)>(15,15,301,301.5)
            typerwrite.complete_block = {[weak self] in //不加weak self会导致无法触发deinit
                self?.alertMessage("打印完成")
            }
            print("%@,%.1f,%.1f",typerwrite.frame,typerwrite.bounds.width,typerwrite.bounds.height)
        }
    }
    
    override func clickRightbarItem() {
        if let typerwrite = mTyper{
            typerwrite.startTyperwrite()
        }
    }

}
